package com.ibuonline.b2b.entity;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import com.dimeng.common.util.StringUtil;
import com.ibuonline.b2b.common.ResourceUtil;
import com.ibuonline.b2b.common.SysCache;

public class ShopBanner implements Serializable {

	private static final long serialVersionUID = -5374304409513927800L;

	//fields
	private java.lang.Integer id;
	private java.lang.String name;
	private java.lang.String color;
	private java.lang.Boolean free = false;
	private java.lang.Integer displayOrder;

	//default constructor
	public ShopBanner() {
	}

	//getter
	public java.lang.Integer getId() {
		return id;
	}
	public java.lang.String getName() {
		return name;
	}
	public java.lang.String getColor() {
		return color;
	}
	public java.lang.Boolean isFree() {
		return free;
	}
	public java.lang.Integer getDisplayOrder() {
		return displayOrder;
	}

	//setter
	public void setId(java.lang.Integer id) {
		this.id = id;
	}
	public void setName(java.lang.String name) {
		this.name = name;
	}
	public void setColor(java.lang.String color) {
		this.color = color;
	}
	public void setFree(java.lang.Boolean free) {
		this.free = free;
	}
	public void setDisplayOrder(java.lang.Integer displayOrder) {
		this.displayOrder = displayOrder;
	}

	//equals method
	public boolean equals(Object other) {
		if (this == other)
			return true;
		if (!(other instanceof ShopBanner))
			return false;

		final ShopBanner shopBanner = (ShopBanner)other;
		if (!this.id.equals(shopBanner.getId()))
			return false;

		return true;
	}

	//hashCode method
	public int hashCode() {
		StringBuffer keys = new StringBuffer();
		keys.append(id).append(",");
		if (keys.length() > 0)
			keys.deleteCharAt(keys.length() - 1);
		return keys.toString().hashCode();
	}

	//toString method
	public String toString() {
		return new StringBuilder("ShopBanner[")
			.append("id=").append(id).append(", ")
			.append("name=").append(name).append(", ")
			.append("color=").append(color).append(", ")
			.append("free=").append(free).append(", ")
			.append("displayOrder=").append(displayOrder).append("]").toString();
	}
	
	///###
	private Integer catId;
	private String catIds;
	
	private Integer useNum;
	private String useNumOrder;
	
	
	public String getShowPhoto() {
		if(id != null) {
			System.out.println(ResourceUtil.getResPath(id+"") + "----");
			return ResourceUtil.getResPath(id+"");
		} else {
			return "/images/logo_default.jpg";
		}
	}
	
	public String getShowColor() {
		if(color != null) {
			color = SysCache.getOptionName("StyleColor", color);
		}
		return color;
	}

	public Integer getUseNum() {
		return useNum;
	}

	public void setUseNum(Integer useNum) {
		this.useNum = useNum;
	}

	public String getUseNumOrder() {
		return useNumOrder;
	}

	public void setUseNumOrder(String useNumOrder) {
		this.useNumOrder = useNumOrder;
	}

	public Integer getCatId() {
		return catId;
	}
	public String getCatIds() {
		return catIds;
	}

	public void setCatIds(String catIds) {
		this.catIds = catIds;
	}

	public void setCatId(Integer catId) {
		this.catId = catId;
	}

	public String getCatName() {
		if(StringUtil.notEmpty(catIds)) {
			String catName = "";
			String[] tempIds = catIds.split(",");
			for(int i=0; i<tempIds.length; i++) {
				catName += SysCache.getCategory(Integer.parseInt(tempIds[i].trim())).getName() + ",";
			}
			if(catName.length() > 0) {
				return catName.substring(0, catName.lastIndexOf(","));
			}
		}
		return "";
	}
	
	public Map<Integer, String> getCatMap() {
		Map<Integer, String> catMap = new HashMap<Integer, String>();
		if(StringUtil.notEmpty(catIds)) {
			String[] tempIds = catIds.split(",");
			for(int i=0; i<tempIds.length; i++) {
				int tempId = Integer.parseInt(tempIds[i].trim());
				String catName = SysCache.getCategory(tempId).getName();
				catMap.put(tempId, catName);
			}
		}
		return catMap;
	}

	public java.lang.Boolean getFree() {
		return free;
	}
	
	public String getBannerDisplayOrder() {
		if(free) {
			return "f"+displayOrder;
		} else {
			return displayOrder+"";	
		}
	}
}